package com.tianqu.tms.www.transfer.controller;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.core.security.TmsUserProfile;
import com.tianqu.tms.entity.TransferAcceptedInfo;
import com.tianqu.tms.entity.TransferProcessHistory;

public class TransferSeniorOutAccUnchainController extends TmsController {
	private Logger logger = Logger.getLogger(TransferSeniorOutAccUnchainController.class);

	@Override
	public void execute(UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = getTxController();
		try {
			controller.begin();
			String serial = (String)uc.getAttribute("serial");

			TransferAcceptedInfo accept = new TransferAcceptedInfo();
			accept.setStatus(5);
			accept.setSerial(serial);
			accept.updateAcceptStatusAloneBySerial(accept);
			
			// 历史记录
			TmsUserProfile profile = uc.getUserProfile();
			TransferProcessHistory history = new TransferProcessHistory();
			history.setSerial(serial);
			history.setBusinessType(38);
			history.setInsertUserId(profile.getUniqueId());
			history.setReason("");
			history.insertHisInfoAtAssess(history);
			
			controller.commit();
		} catch (Exception e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			// 系统异常
			if (e instanceof TmsException) {
				throw e;
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}
		logger.debug(this.getClass().getName() + "#execute was completed.");
	}

}
